-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bwc for parsing mappings from dynamic templates #67763
Conversation
During refactoring of the mapper parsing code, the part that checks for unknown mapper parameters and throws an error when one is found was moved to FieldMapper.Builder#parse which gets also executed when applying matching dynamic templates. However, dynamic templates introduced during the 7.x versions may still contain arbitrary parameters, although we have deprecation warnings for that in place on latest 7.x now. When using these templates, indexing a new document with a new field that triggers one of these mappings to be parsed can create an error as demonstrated in elastic#66765. Instead we need to be lenient in these cases and simply ignore the unknown parameter while issuing a deprecation warning here as well. Closes elastic#66765
Pinging @elastic/es-search (Team:Search) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation LGTM, I think the integration test needs uncommenting though?
.put("index.version.created", VersionUtils.randomPreviousCompatibleVersion(random(), Version.V_8_0_0)) | ||
).setMapping(mapping).get()); | ||
client().prepareIndex(indexName).setSource("{\"foo\" : \"bar\"}", XContentType.JSON).get(); | ||
// assertNoFailures((client().admin().indices().prepareRefresh(indexName)).get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, course
@@ -990,8 +990,21 @@ public final void parse(String name, ParserContext parserContext, Map<String, Ob | |||
iterator.remove(); | |||
continue; | |||
} | |||
throw new MapperParsingException("unknown parameter [" + propName | |||
+ "] on mapper [" + name + "] of type [" + type + "]"); | |||
if (parserContext.isFromDynamicTemplate() && parserContext.indexVersionCreated().before(Version.V_8_0_0)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can have a dynamic template in an index >8.0.0 with a malformed parameter since we cannot add it, but I put the version check here regardless for safety. @romseygeek wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
// ); | ||
// assertThat(ex.getMessage(), containsString("dynamic template [my_template] has invalid content")); | ||
assertNoFailures((client().admin().indices().prepareRefresh(indexName)).get()); | ||
assertHitCount(client().prepareSearch(indexName).get(), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assert that we get a deprecation warning from the index action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was looking at how to do that in Integ tests but couldn't find any pointers. ESIntegTestCase#enableWarningsCheck makes me think its not possible here, but if you have pointers to tests doing this I'm happy to add it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call getWarnings()
on the response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this IndexResponse is no org.elasticsearch.client.Response
, will check if there are other ways...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's no way of doing it then let's get this merged anyway.
During refactoring of the mapper parsing code, the part that checks for unknown mapper parameters and throws an error when one is found was moved to FieldMapper.Builder#parse which gets also executed when applying matching dynamic templates. However, dynamic templates introduced during the 7.x versions may still contain arbitrary parameters, although we have deprecation warnings for that in place on latest 7.x now. When using these templates, indexing a new document with a new field that triggers one of these mappings to be parsed can create an error as demonstrated in elastic#66765. Instead we need to be lenient in these cases and simply ignore the unknown parameter while issuing a deprecation warning here as well. Closes elastic#66765
During refactoring of the mapper parsing code, the part that checks for unknown mapper parameters and throws an error when one is found was moved to FieldMapper.Builder#parse which gets also executed when applying matching dynamic templates. However, dynamic templates introduced during the 7.x versions may still contain arbitrary parameters, although we have deprecation warnings for that in place on latest 7.x now. When using these templates, indexing a new document with a new field that triggers one of these mappings to be parsed can create an error as demonstrated in elastic#66765. Instead we need to be lenient in these cases and simply ignore the unknown parameter while issuing a deprecation warning here as well. Closes elastic#66765
During refactoring of the mapper parsing code, the part that checks for unknown mapper parameters and throws an error when one is found was moved to FieldMapper.Builder#parse which gets also executed when applying matching dynamic templates. However, dynamic templates introduced during the 7.x versions may still contain arbitrary parameters, although we have deprecation warnings for that in place on latest 7.x now. When using these templates, indexing a new document with a new field that triggers one of these mappings to be parsed can create an error as demonstrated in #66765. Instead we need to be lenient in these cases and simply ignore the unknown parameter while issuing a deprecation warning here as well. Closes #66765
During refactoring of the mapper parsing code, the part that checks for unknown mapper parameters and throws an error when one is found was moved to FieldMapper.Builder#parse which gets also executed when applying matching dynamic templates. However, dynamic templates introduced during the 7.x versions may still contain arbitrary parameters, although we have deprecation warnings for that in place on latest 7.x now. When using these templates, indexing a new document with a new field that triggers one of these mappings to be parsed can create an error as demonstrated in #66765. Instead we need to be lenient in these cases and simply ignore the unknown parameter while issuing a deprecation warning here as well. Closes #66765
During refactoring of the mapper parsing code, the part that checks for unknown
mapper parameters and throws an error when one is found was moved to
FieldMapper.Builder#parse which gets also executed when applying matching
dynamic templates. However, dynamic templates introduced during the 7.x versions
may still contain arbitrary parameters, although we have deprecation warnings
for that in place on latest 7.x now. When using these templates, indexing a new
document with a new field that triggers one of these mappings to be parsed can
create an error as demonstrated in #66765. Instead we need to be lenient in
these cases and simply ignore the unknown parameter while issuing a deprecation
warning here as well.
Closes #66765